package com.huangbc.apiDriver.controller;

import com.huangbc.internalcommon.constant.DriverCarConstants;
import com.huangbc.internalcommon.dto.DriverUserWorkStatus;
import com.huangbc.internalcommon.remote.ServiceDriverUserClient;
import com.huangbc.internalcommon.remote.ServiceOrderClient;
import com.huangbc.internalcommon.request.OrderRequest;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: Derek.huang on 2024/3/29 18:44.
 */
@RestController
public class TestController {

    /**
     * 需要授权的接口
     * @return
     */
    @GetMapping("/auth")
    public String testAuth(){
        return  "auth";
    }

    /**
     * 不需要授权的接口
     * @return
     */
    @GetMapping("/noauth")
    public String testNoAuth(){
        return "no auth";
    }


    @Autowired
    ServiceDriverUserClient serviceDriverUserClient;

    @Autowired
    ServiceOrderClient serviceOrderClient;

    /**
     * seata 事务测试。
     */
    @GetMapping("/test-GlobalTransactional")
    @GlobalTransactional
    public void test(){
        DriverUserWorkStatus driverUserWorkStatus = new DriverUserWorkStatus();
        driverUserWorkStatus.setDriverId(998L);
        driverUserWorkStatus.setWorkStatus(DriverCarConstants.DRIVER_WORK_STATUS_SERVING);
        serviceDriverUserClient.changeWorkStatus(driverUserWorkStatus);
        int a = 1/0;
        OrderRequest orderRequest = new OrderRequest();
        orderRequest.setOrderId(998L);
        orderRequest.setPassengerId(998L);
        orderRequest.setReceiveOrderCarLatitude("999");
        serviceOrderClient.passengerGetoff(orderRequest);
    }
}

